<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 添加防止缓存的meta标签 -->
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <title>用户注册 - 会议室预订系统</title>
    <!-- 引入Font Awesome图标库 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        /* 重置默认样式并设置全局字体 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        /* 页面背景设置 */
        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        /* 主容器样式 */
        .container {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
            width: 100%;
            max-width: 500px;
            padding: 40px;
            position: relative;
            overflow: hidden;
            text-align: center;
        }

        /* 容器装饰效果 */
        .container::before {
            content: '';
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
            transform: rotate(45deg);
            z-index: -1;
        }

        /* 头部样式 */
        .header {
            margin-bottom: 30px;
        }

        /* 标题样式 */
        h1 {
            color: #333;
            font-size: 2.5rem;
            margin-bottom: 10px;
            background: linear-gradient(135deg, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        /* 描述文字样式 */
        .description {
            color: #666;
            font-size: 1.1rem;
            margin-bottom: 30px;
        }

        /* 表单组样式 */
        .form-group {
            margin-bottom: 20px;
            text-align: left;
        }

        /* 标签样式 */
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #333;
        }

        /* 输入框容器样式 */
        .input-with-icon {
            position: relative;
        }

        /* 图标样式 */
        .input-with-icon i {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: #667eea;
        }

        /* 输入框样式 */
        .input-with-icon input {
            width: 100%;
            padding: 15px 15px 15px 45px;
            border: 2px solid #e1e1e1;
            border-radius: 10px;
            font-size: 16px;
            transition: border-color 0.3s;
        }

        /* 输入框焦点样式 */
        .input-with-icon input:focus {
            border-color: #667eea;
            outline: none;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
        }

        /* 错误信息样式 */
        .error-message {
            color: #e74c3c;
            min-height: 20px;
            margin: 15px 0;
            font-weight: 500;
        }

        /* 按钮样式 */
        button {
            width: 100%;
            padding: 15px;
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: white;
            border: none;
            border-radius: 10px;
            font-size: 1.1rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        }

        /* 按钮悬停效果 */
        button:hover {
            transform: translateY(-3px);
            box-shadow: 0 7px 20px rgba(0, 0, 0, 0.15);
        }

        /* 按钮按下效果 */
        button:active {
            transform: translateY(0);
        }

        /* 登录链接样式 */
        .login-link {
            margin-top: 20px;
            color: #666;
        }

        /* 链接样式 */
        .login-link a {
            color: #667eea;
            text-decoration: none;
            font-weight: 600;
        }

        /* 链接悬停效果 */
        .login-link a:hover {
            text-decoration: underline;
        }

        /* 页脚样式 */
        .footer {
            margin-top: 30px;
            color: #999;
            font-size: 0.9rem;
        }

        /* 响应式设计 */
        @media (max-width: 600px) {
            .container {
                padding: 30px 20px;
            }
            
            h1 {
                font-size: 2rem;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <div class="header">
        <h1><i class="fas fa-calendar-alt"></i> 会议室预订系统</h1>
        <p class="description">请输入您的账户信息注册</p>
    </div>

    <!-- 注册表单 -->
    <form id="registerForm">
        <div class="form-group">
            <label for="username">用户名</label>
            <div class="input-with-icon">
                <i class="fas fa-user"></i>
                <input type="text" id="username" name="username" placeholder="请输入用户名" required>
            </div>
        </div>

        <div class="form-group">
            <label for="password">密码</label>
            <div class="input-with-icon">
                <i class="fas fa-lock"></i>
                <input type="password" id="password" name="password" placeholder="请输入密码" required>
            </div>
        </div>
        <!-- 错误信息显示区域 -->
        <div id="errorMessage" class="error-message" role="alert" aria-live="assertive"></div>
        <!-- 注册按钮 -->
        <button type="submit" id="registerButton">
            <span class="button-text">注册</span>
        </button>
    </form>
    
    <div class="login-link">
        <p>如果已经注册了，请<a href="/api/login.html">登录</a></p>
    </div>
    
    <div class="footer">
        <p>© 2025 会议室预订系统. 保留所有权利.</p>
    </div>
    
    <script>
        document.getElementById('registerForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            // 获取按钮和错误信息元素
            const registerButton = document.getElementById('registerButton');
            const errorMessage = document.getElementById('errorMessage');
            const buttonText = registerButton.querySelector('.button-text');
            
            // 获取表单数据
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            
            // 简单验证
            if (!username || !password) {
                errorMessage.textContent = '请输入用户名和密码';
                return;
            }
            
            // 显示加载状态
            buttonText.textContent = '注册中...';
            registerButton.disabled = true;
            
            // 创建用户对象
            const user = {
                username: username,
                password: password
            };
            
            // 发送注册请求
            fetch('/api/user/register', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(user)
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    errorMessage.style.color = '#27ae60';
                    errorMessage.textContent = '注册成功，正在跳转到登录页面...';
                    setTimeout(() => {
                        window.location.href = '/api/login.html';
                    }, 1500);
                } else {
                    errorMessage.style.color = '#e74c3c';
                    errorMessage.textContent = data.message || '注册失败';
                }
            })
            .catch(error => {
                console.error('Error:', error);
                errorMessage.style.color = '#e74c3c';
                errorMessage.textContent = '注册请求失败，请检查网络连接';
            })
            .finally(() => {
                // 恢复按钮状态
                buttonText.textContent = '注册';
                registerButton.disabled = false;
            });
        });
    </script>
</div>
</body>
</html>